#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 +5;
struct pos
{
    int d, v, a;
}car[MAXN];


int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int T;
    cin >> T;
    for(int z = 1; z < T; z++)
    {
        int n, m, L, V, ans = 0;
        cin >> n >> m >> L >> V;
        for(int i = 1; i <= n; i++)
            cin >> car[i].d >> car[i].v >> car[i].a;
        for(int j = 1; j <= n; j++)
            if(car[j].v > V) ans++;
        printf("%d %d", ans, m - 1);
    }
    return 0;
}